
// Definition for a binary tree node.
function TreeNode(val, left, right) {
    this.val = (val===undefined ? 0 : val)
    this.left = (left===undefined ? null : left)
    this.right = (right===undefined ? null : right)
}

/**
 * @param {TreeNode} root
 * @return {boolean}
 */
var isUnivalTree = function(root) {
  if(!root) return root;
  let val = root.val, result = true;
  function preView(node) {
    if(!node) return ;
    if(node.val != val) {
      result = false;
      return;
    }
    preView(node.left);
    preView(node.right);
  }
  preView(root);
  return result;
};
